/*
 * @Author: Nxf
 * @Date: 2024-05-17 08:53:07
 * @LastEditors: Nxf
 * @LastEditTime: 2024-07-28 19:31:01
 * @Descripttion:
 */
// for web browser, use  axios
import { Request } from './request_axios.js'
//
// for wx mp, use wx request
// import { Request } from './request_wx.js'

// for local odoojs-rpc
// import { get_odoojs_rpc } from 'odoojs-rpc'
//
// for npm odoojs-rpc
import { get_odoojs_rpc } from '@/odoojs-rpc/index.js'

export function sleep(millisecond) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve()
    }, millisecond)
  })
}

function messageError(error) {
  console.log('error', error)
  console.log('show error', error.message)

  return Promise.reject(error)
}

// 开发时, 值为 '/api', 打包部署后, 值为 '/odoo'
const baseURL = import.meta.env.VITE_BASE_API
const timeout = 50000
const run_by_server = false // to set true if addons of web_for_odoojs installed

export function get_api() {
  const rpc = get_odoojs_rpc({
    Request,
    baseURL,
    timeout,
    run_by_server,
    messageError
  })
  return rpc
}
